package ioperation;

import book.BookList;

import java.util.Scanner;

public class DelOperation implements IOperations{
    @Override
    public void work(BookList bookList) {
        System.out.println("--------删除图书--------");
        System.out.println("请输入你要删除的图书的名字：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int i = 0;
        int pos = 0;
        int currentSize = bookList.getUsedSize();
        for(i = 0; i < currentSize; i++) {
            if(bookList.getBook(i).equals(name)) {
                pos = i;
                break;
            }
        }

        if(i == bookList.getBooks().length) {
            //没有找到你要删除的书
            System.out.println("删除失败,没有找到你要删除的书!!!");
        }
        for ( i = pos; i < currentSize - 1; i++) {
            bookList.setBook(bookList.getBook(i + 1), i);
        }
        bookList.setUsedSize(currentSize - 1);
    }
}
